/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cripto;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author akono
 */
public class Cripto {

//extensao cpt é do arquivo criptografado
    public boolean criarArquivoBinario(String docOrigem, String docCrip) {
        //arquivo a ser criptografado
        File arq = new File(docOrigem);

        try {
            //leitura
            FileInputStream fi = new FileInputStream(arq);            
            BufferedInputStream leitura = new BufferedInputStream(fi);
            
            //gravacao
            FileOutputStream fo = new FileOutputStream(docCrip);            
            BufferedOutputStream out = new BufferedOutputStream(fo);
                        
            //vai pegar um byte do arquivo
            int b;
            int byteC;
            byte[] bloco = new byte[32];            
            
            //le arquivo ate final
            while ((b = leitura.read(bloco)) != -1) {
                //pega byte ciptografado por inversao de bits
                //byteC = getByteCriptografado((byte) b);
                byte[] bx = new byte[32];
                
                for (int i = 0; i < bloco.length; i++) {
                    //bx[i] = (byte) Integer.reverseBytes(bloco[i]);
                    bx[i] = bloco[i];
                }
                out.write(bx);
            }
            
            //encerrando
            leitura.close();
            out.flush();
            out.close();

        } catch (FileNotFoundException ex) {
            Logger.getLogger(Cripto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Cripto.class.getName()).log(Level.SEVERE, null, ex);
        }

        return true;
    }

    private byte getByteCriptografado(byte byteOriginal) {
//aqui vai implementar rotina onde deve inverter os bits, se 0 entao 1; 
        return 1;
    }
    
    public static void main(String[] args) {
        
        /*String origem = "C:\\temp\\testePOO\\1__Pratica_Gerenciamento_de_Buffer.pdf";
        String destino = "C:\\temp\\testePOO\\copia.pdf";*/
        String origem = "C:\\temp\\testePOO\\copia.pdf";
        String destino = "C:\\temp\\testePOO\\copia2.pdf";
        
        Cripto cripto = new Cripto();
        cripto.criarArquivoBinario(origem, destino);
    }
    
    private String getCabecalho(){
        
        return "";
    }

}
